home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11536 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: sun.uakom.sk!news
  2. From: Stefan Billik <billik@sun.uniag.sk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: rand ?
  5. Date: Mon, 25 Mar 1996 08:16:25 -0100
  6. Organization: steve
  7. Distribution: world
  8. Message-ID: <31566469.1596@sun.uniag.sk>
  9. References: <4idjt4$4du@itsop2.its.brooklyn.cuny.edu> <314BB352.2734@ccis.com> <mjs.827088266@hubcap>
  10. NNTP-Posting-Host: sun.uniag.sk
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=iso-8859-2
  13. Content-Transfer-Encoding: 7bit
  14. X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.4 sun4m)
  15.  
  16. > #include <stdlib.h>
  17. > >#define RANDOMIZE() srand(time(NULL)) /* time() is in time.h */
  18. > >main()
  19. > >{
  20. > > int i ;
  21. > > while(i != 0 )
  22. > >  printf("%d\n",i = random(52));
  23. > >}
  24. > > int random(int i)
  25. > > {
  26. > >  double x = RAND_MAX + 1.0 ;/* RAND_MAX is defined in stdlib.h */
  27. > >  int y ;
  28. > >  RANDOMIZE();
  29. > >  y = 1 + rand() * (i /x) ;
  30. > >  return y ;
  31. > > }
  32.  
  33. >                 Matthew Saltzman
  34. >                 Clemson University Math Sciences
  35. >                 mjs@clemson.edu
  36.  
  37. /* HERE IS ANOTHER QUESTION: */
  38. I am using gcc and cc at SunOS 5.4, and I am wonder, if RAND_MAX is
  39. defined for each compiler differently;?
  40. ?Look at this:
  41.  
  42.  08:10 /usr1/users/student/billik/C/# cc c/random.c
  43.  08:10 /usr1/users/student/billik/C/# a.out
  44. 478513
  45.  08:10 /usr1/users/student/billik/C/# gcc c/random.c 
  46.  08:10 /usr1/users/student/billik/C/# a.out
  47. 15
  48.  08:10 /usr1/users/student/billik/C/# 
  49.  
  50. PS: can You help me ?
  51.  
  52.  
  53. -- 
  54.     \\|//                                                 \\|//
  55.     (o o)           http://sun.uniag.sk/~billik           (o o)
  56. -ooO-(_)-Ooo-------------------------------------------ooO-(_)-Ooo-
  57.  billik@afnet.uniag.sk && billik@sun.uniag.sk && billik@sai.uniag.sk
  58.                                                              steve.
  59.